//
//  PhoneNumberUtils.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/6/19.
//

import SwiftUI


struct PhoneNumberMask {
    /// 基础版：简单替换中间四位
    static func mask(_ phone: String) -> String {
        guard phone.count == 11 else { return phone }
        return "\(phone.prefix(3))****\(phone.suffix(4))"
    }
    
    /// 正则验证版：确保1开头的11位数字
    static func maskWithValidation(_ phone: String) -> String {
        let pattern = "^1[0-9]{10}$"
        guard phone.range(of: pattern, options: .regularExpression) != nil else {
            return phone
        }
        return mask(phone)
    }
}
